<template>
  <el-container>
    <el-aside width="220px">
      <!-- logo -->
      <div class="logo"></div>
      <!-- 调用Navbar组件 -->
      <Navbar />
    </el-aside>
    <el-container>
      <el-header>
        <el-dropdown class="admin-dropdown">
          <span class="el-dropdown-link">
            {{adminInfo.username}}<i class="el-icon-arrow-down el-icon--right"></i>
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item>
              <div @click="logout">安全退出</div>
            </el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </el-header>
      <el-main>
        <!-- 二级路由占位符 -->
        <router-view />
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import { mapState,mapMutations } from 'vuex';
// 导入导航菜单组件
import Navbar from "../components/Navbar";
export default {
  components: { Navbar },
  computed:{
    ...mapState(['adminInfo'])
  },
  methods: {
    ...mapMutations(['adminInit']),
    // 安全退出
    logout() {
      // 1-清除本地存储中的登录信息
      localStorage.removeItem("adminInfo");
      // 2-成功提示
      this.$message.success("退出成功");
      // 3-自动跳转到登录页面
      this.$router.push("/login");
    },
  },
  created(){
    // 初始化当前登录账号信息
    this.adminInit();
  }
};
</script>

<style scoped>
/* scoped: scoped只会对组件内部的样式添加作用域 */
@import url("../assets/css/common.css");
.el-container {
  height: 100vh;
}
.logo {
  height: 60px;
  width: 100%;
  background: url("../assets/imgs/logo-white.png") #ff674b no-repeat center
    center;
  background-size: 60%;
}
ul.el-menu-vertical {
  height: calc(100% - 60px);
  border-right: 0;
}
.el-header {
  background-color: #fff;
  color: #333;
  line-height: 60px;
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
  line-height: 200px;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
}
.admin-dropdown {
  position: absolute;
  top: 0px;
  right: 10px;
}
</style>
